﻿using System;
using System.Data;
using System.Data.SqlClient;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Csla;

namespace Model
{
    [Serializable()]
    public class BacLuongReduceBOCollection : Csla.BusinessListBase<BacLuongReduceBOCollection, BacLuongReduceBO>
    {
        #region BindingList Overrides
        protected override object AddNewCore()
        {
            BacLuongReduceBO _BacLuongReduceBO = BacLuongReduceBO.NewChildBacLuongReduceBO();
            OnAddingNew(new System.ComponentModel.AddingNewEventArgs(_BacLuongReduceBO));
            Add(_BacLuongReduceBO);
            return _BacLuongReduceBO;
        }
        #endregion BindingList Overrides
        //==========================================================================

        #region Factory Methods
        private BacLuongReduceBOCollection()
        {
        }

        public static BacLuongReduceBOCollection NewBacLuongReduceBOCollection()
        {
            return new BacLuongReduceBOCollection();
        }

        public static BacLuongReduceBO NewBacLuongReduceBO()
        {
            return BacLuongReduceBO.NewChildBacLuongReduceBO();
        }

        public static BacLuongReduceBOCollection GetBacLuongReduceBOCollection()
        {
            SPParam spParam = new SPParam("NgachLuongID,SoThuTu", "ASC", "WHERE DELE=0");
            return DataPortal.Fetch<BacLuongReduceBOCollection>(spParam);
        }

        public static BacLuongReduceBOCollection GetBacLuongReduceBOCollection(bool getDeleted)
        {
            SPParam spParam = new SPParam("NgachLuongID,SoThuTu", "ASC", "");
            return DataPortal.Fetch<BacLuongReduceBOCollection>(spParam);
        }

        public static BacLuongReduceBOCollection GetBacLuongReduceBOCollection(string where)
        {
            SPParam spParam = new SPParam("NgachLuongID,SoThuTu", "ASC", "WHERE DELE=0" + (where != "" ? " AND " : "") + where);
            return DataPortal.Fetch<BacLuongReduceBOCollection>(spParam);
        }

        public static BacLuongReduceBOCollection GetBacLuongReduceBOCollection(string where, bool getDeleted)
        {
            SPParam spParam = new SPParam("NgachLuongID,SoThuTu", "ASC", (where != "" ? "WHERE " : "") + where);
            return DataPortal.Fetch<BacLuongReduceBOCollection>(spParam);
        }

        public static BacLuongReduceBOCollection GetBacLuongReduceBOCollection(string where, string orderByColumn)
        {
            SPParam spParam = new SPParam((orderByColumn == "" ? "NgachLuongID,SoThuTu" : orderByColumn), "ASC", "WHERE DELE=0" + (where != "" ? " AND " : "") + where);
            return DataPortal.Fetch<BacLuongReduceBOCollection>(spParam);
        }

        public static BacLuongReduceBOCollection GetBacLuongReduceBOCollection(string where, string orderByColumn, bool getDeleted)
        {
            SPParam spParam = new SPParam((orderByColumn == "" ? "NgachLuongID,SoThuTu" : orderByColumn), "ASC", (where != "" ? "WHERE " : "") + where);
            return DataPortal.Fetch<BacLuongReduceBOCollection>(spParam);
        }

        public static BacLuongReduceBOCollection GetBacLuongReduceBOCollection(string where, string orderByColumn, string orderByExpression)
        {
            SPParam spParam = new SPParam((orderByColumn == "" ? "NgachLuongID,SoThuTu" : orderByColumn), (orderByExpression == "" ? "ASC" : orderByExpression), "WHERE DELE=0" + (where != "" ? " AND " : "") + where);
            return DataPortal.Fetch<BacLuongReduceBOCollection>(spParam);
        }

        public static BacLuongReduceBOCollection GetBacLuongReduceBOCollection(string where, string orderByColumn, string orderByExpression, bool getDeleted)
        {
            SPParam spParam = new SPParam((orderByColumn == "" ? "NgachLuongID,SoThuTu" : orderByColumn), (orderByExpression == "" ? "ASC" : orderByExpression), (where != "" ? "WHERE " : "") + where);
            return DataPortal.Fetch<BacLuongReduceBOCollection>(spParam);
        }
        #endregion Factory Methods
        //==========================================================================

        #region Criteria
        [Serializable()]
        private class Criteria
        {
            public Criteria()
            {
            }
        }

        [Serializable()]
        public class FilterCriteria
        {
            public FilterCriteria()
            {
            }
        }
        #endregion Criteria
        //==========================================================================

        #region Fetch
        [Transactional(TransactionalTypes.TransactionScope)]
        private void DataPortal_Fetch(SPParam spParam)
        {
            RaiseListChangedEvents = false;
            SqlDatabase db = new SqlDatabase(Session.DBConnectionString);
            SqlCommand cmd = (SqlCommand)db.GetStoredProcCommand("BacLuongReduceBO_SelectBOCollection");
            db.AddInParameter(cmd, "@OrderColumn", SqlDbType.VarChar, (object)spParam.orderColumn);
            db.AddInParameter(cmd, "@OrderExpression", SqlDbType.VarChar, (object)spParam.orderExpression);
            db.AddInParameter(cmd, "@WhereExpression", SqlDbType.NVarChar, (object)spParam.whereExpression);
            using (SqlDataReader dr = (SqlDataReader)db.ExecuteReader(cmd))
            {
                while (dr.Read())
                {
                    BacLuongReduceBO objBacLuongReduceBO = BacLuongReduceBO.GetChildBacLuongReduceBO(dr);
                    this.Add(objBacLuongReduceBO);
                }
            }
            RaiseListChangedEvents = true;
        }
        #endregion Fetch
        //==========================================================================

        #region Update
        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_Update()
        {
            Update();
        }

        internal void Update()
        {
        }
        #endregion Update
        //==========================================================================

        #region Business Method
        public BacLuongReduceBO GetBacLuongReduceBO(int _BacLuongID)
        {
            int length = this.Count;
            for (int i = 0; i < length; i++)
                if (this[i].BacLuongID == _BacLuongID)
                    return this[i];

            return null;
        }

        public BacLuongReduceBOCollection FilterData(int NgachLuongID)
        {
            BacLuongReduceBOCollection bacLuongReduceBOCollection = BacLuongReduceBOCollection.NewBacLuongReduceBOCollection();
            int length = this.Count;
            for (int i = 0; i < length; i++)
            {
                if (this[i].NgachLuongID != null)
                    if (this[i].NgachLuongID.Value == NgachLuongID)
                        bacLuongReduceBOCollection.Add(this[i]);
            }

            return bacLuongReduceBOCollection;
        }

        public void Remove(int BacLuongID)
        {
            int length = this.Count;
            for (int i = 0; i < length; i++)
            {
                if (this[i].BacLuongID == BacLuongID)
                {
                    try
                    {
                        this.RemoveAt(i);
                    }
                    catch { }
                    break;
                }
            }
        }
        #endregion Business Method
        //==========================================================================
    }
}
